home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / info-service / www / src / midaswww-1.0 / SGMLListText.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-11-16  |  10.7 KB  |  287 lines

  1. /*==================================================================*/
  2. /*                                                                  */
  3. /* SGMLListTextObject                                               */
  4. /*                                                                  */
  5. /* T.Johnson - (TonyJ@Slacvx.Slac.Stanford.Edu)           June.92   */
  6. /*                                                                  */
  7. /* Defines a list text segment for the SGMLHyper widget             */
  8. /*                                                                  */
  9. /*==================================================================*/
  10.  
  11. #include <X11/IntrinsicP.h>
  12. #include <X11/StringDefs.h>
  13. #include "SGMLListTextP.h"
  14.  
  15. /* 
  16.   Private functions 
  17. */
  18.  
  19.  
  20. /*
  21.   Widget class methods
  22. */
  23.  
  24. static void             ClassInitialize();
  25. static void            Initialize();
  26. static void            Destroy();
  27. static void             ComputeSize();
  28. static Boolean          AdjustSize();
  29. static void             Redisplay();
  30.  
  31. #define Offset(field) XtOffsetOf(SGMLListTextRec,sgml_list_text.field)
  32.  
  33. static XtResource resources[] = {
  34.  
  35.     {SGMLNnumBullets, XtCReadOnly, XtRInt, sizeof(int),
  36.      Offset(num_bullets), XtRImmediate, (XtPointer) 0},
  37.     {SGMLNallocBullets, XtCReadOnly, XtRInt, sizeof(int),
  38.      Offset(alloc_bullets), XtRImmediate, (XtPointer) 0},
  39.  
  40.     {SGMLNbulletType, SGMLCBulletType, SGMLRBulletType, sizeof(int),
  41.      Offset(bullet_type), XtRImmediate, (XtPointer) SGMLBULLET_DEFAULT},
  42.     {SGMLNbulletSize, SGMLCBulletSize, XtRDimension, sizeof(Dimension),
  43.      Offset(bullet_size), XtRImmediate, (XtPointer) 10},
  44.     {SGMLNbulletIndent, SGMLCBulletIndent, XtRDimension, sizeof(Dimension),
  45.      Offset(bullet_indent), XtRImmediate, (XtPointer) 5},
  46.     {SGMLNbulletColor, SGMLCBulletColor, XtRPixel, sizeof(Pixel),
  47.      Offset(bullet_color), XtRImmediate, (XtPointer) 0}
  48. };
  49. #undef Offset
  50.  
  51. /*---------------------------------------------------------------*/
  52. /* Static initialisation of the class record                     */
  53. /*---------------------------------------------------------------*/
  54.  
  55. SGMLListTextClassRec  sGMLListTextClassRec = {
  56.     {
  57.     (WidgetClass) &sGMLCompositeTextClassRec,
  58.                                          /* superclass            */
  59.     "SGMLListText",                      /* class_name            */
  60.     sizeof(SGMLListTextRec),             /* widget_size           */
  61.     ClassInitialize,                     /* class_initialize      */
  62.     NULL,                                /* class_part_initialize */
  63.     FALSE,                               /* class_inited          */
  64.     Initialize,                          /* initialize            */
  65.     NULL,                                /* initialize_hook       */
  66.     NULL,                                /* obj1                  */
  67.     NULL,                                /* obj2                  */
  68.     0,                                   /* obj3                  */
  69.     resources,                           /* resources             */
  70.     XtNumber(resources),                 /* num_resources         */
  71.     NULLQUARK,                           /* xrm_class             */
  72.     0,                                   /* obj4                  */
  73.     0,                                   /* obj5                  */
  74.     0,                                   /* obj6                  */
  75.     0,                                   /* obj7                  */
  76.     Destroy,                             /* destroy               */
  77.     NULL,                                /* obj8                  */
  78.     NULL,                                /* obj9                  */
  79.     NULL,                                /* set_values            */
  80.     NULL,                                /* set_values_hook       */
  81.     NULL,                                /* obj10                 */
  82.     NULL,                                /* get_values_hook       */
  83.     NULL,                                /* obj11                 */
  84.     XtVersion,                           /* version               */
  85.     NULL,                                /* callback private      */
  86.     NULL,                                /* obj12                 */
  87.     NULL,                                /* obj13                 */
  88.     NULL,                                /* obj14                 */
  89.     NULL,                                /* extension             */
  90.     },
  91.     {
  92.     ComputeSize,                   /* compute_size          */
  93.     SGMLInheritAdjustSize,               /* adjust_size           */
  94.     SGMLInheritAdjustPosition,        /* adjust_position       */
  95.     Redisplay,                           /* expose                */
  96.     SGMLInheritActivate,                 /* activate              */
  97.     SGMLInheritHilite,                   /* hilite                */
  98.     SGMLInheritContains,                 /* contains              */
  99.     SGMLInheritCallCreateCallback,       /* call_create_callback  */
  100.     SGMLInheritCallMapCallback,          /* call_map_callback     */
  101.     SGMLInheritMakeVisible,              /* make_visible          */
  102.     NULL,                                /* extension             */
  103.     },
  104.     {
  105.     NULL,                                /* geometry_manager      */
  106.     NULL,                                /* change_managed        */
  107.     XtInheritInsertChild,                /* insert_child          */
  108.     XtInheritDeleteChild,                /* delete_child          */
  109.     NULL,                                /* ignore                */
  110.     },
  111.     {
  112.     NULL                                 /* ignore                */
  113.     }
  114. };
  115.  
  116. WidgetClass sGMLListTextObjectClass = (WidgetClass) &sGMLListTextClassRec;
  117.  
  118. /*--------------------------------------------------------------*/
  119. /* ClassInitialize:                                             */
  120. /*--------------------------------------------------------------*/
  121.  
  122. static void ClassInitialize()
  123. {
  124. }
  125.  
  126. /*--------------------------------------------------------------*/
  127. /* Initialize:                                                  */
  128. /*--------------------------------------------------------------*/
  129.  
  130. static void Initialize (request, new)
  131. SGMLListTextObject request, new;
  132. {
  133.    new->sgml_list_text.bullets = NULL;
  134.    new->sgml_list_text.num_bullets = 0;
  135.    new->sgml_list_text.alloc_bullets = 0;
  136. }
  137.  
  138. /*--------------------------------------------------------------*/
  139. /* Destroy the widget: release all memory allocated             */
  140. /*--------------------------------------------------------------*/
  141.  
  142. static void Destroy (w)
  143. SGMLListTextObject w;
  144. {
  145.     XtFree((char *) w->sgml_list_text.bullets);
  146. }
  147.  
  148. /*--------------------------------------------------------------*/
  149. /* Redisplay                                                    */
  150. /*--------------------------------------------------------------*/
  151.  
  152. static void Redisplay(t,event,region)
  153. SGMLListTextObject t;
  154. XEvent *event;
  155. Region region;
  156. {
  157. /*
  158.  *   Invoke our superclasses ReDisplay routine ... then draw bullets
  159.  */ 
  160.  
  161.  Display *dpy = XtDisplayOfObject((Widget) t);
  162.  Window  wind = XtWindowOfObject((Widget) t);
  163.  GC gc =  t->sgml_text.gc;
  164.  int i;
  165.   
  166.  SGMLTextObjectClass superclass = (SGMLTextObjectClass) XtSuperclass((Widget) t);
  167.  
  168.  (*superclass->sgml_text_class.expose)(t,event,region); 
  169.   
  170.  for (i = 0; i < t->sgml_list_text.num_bullets; i++ )
  171.    {
  172.      Dimension width = t->sgml_list_text.bullet_size;
  173.      Dimension height = t->sgml_list_text.bullet_size;
  174.      Position x = t->sgml_list_text.bullets[i].x - width;
  175.      Position y = t->sgml_list_text.bullets[i].y;
  176.      
  177.      if(XRectInRegion(region,x,y,width,height) != RectangleOut)
  178.        XFillRectangle(dpy,wind,gc,x,y,width,height);
  179.    } 
  180. }
  181. /*------------------------------------------------------------------*/
  182. /* Adjust the size of a child                                       */
  183. /*------------------------------------------------------------------*/
  184.  
  185. static Boolean AdjustSize(child,y,ascent,depth)
  186. Widget child;
  187. Position y;
  188. Dimension ascent, depth;
  189. {
  190.    SGMLListTextObject w = (SGMLListTextObject) XtParent(child);
  191.    int n = w->sgml_composite_text.num_children;
  192.    WidgetList children = w->sgml_composite_text.children;
  193.    WidgetList p = children; 
  194.    Boolean cont;
  195.   
  196.    for (; n-- > 0; p++)
  197.      if (*p == child)
  198.        {
  199.          for (;  p-- != children ; ) 
  200.            {
  201.              SGMLTextObjectClass childClass = (SGMLTextObjectClass) XtClass(*p);
  202.              cont =  (*childClass->sgml_text_class.adjust_size)(*p,y,ascent,depth);
  203.              if (!cont) return FALSE; 
  204.            }
  205.          return TRUE;
  206.        }      
  207.   return TRUE;
  208. }
  209.  
  210. /*--------------------------------------------------------------*/
  211. /* Compute Size:                                                */
  212. /*--------------------------------------------------------------*/
  213.  
  214. static void ComputeSize(w,geom,Adjust,Closure)
  215. SGMLListTextObject w;
  216. SGMLGeometry *geom;
  217. AdjustSizeProc Adjust;
  218. Opaque Closure;
  219. {
  220.    int n = w->sgml_composite_text.num_children;
  221.    WidgetList children = w->sgml_composite_text.children;
  222.    Dimension maxWidth;
  223.    Position x  = w->sgml_text.left_margin + w->sgml_text.left_indent - w->sgml_list_text.bullet_indent;
  224.  
  225.    XtFree((char *) w->sgml_list_text.bullets);
  226.    w->sgml_list_text.bullets = NULL;
  227.    w->sgml_list_text.num_bullets = 0;
  228.    w->sgml_list_text.alloc_bullets = 0;
  229.    
  230.    /*
  231.     * Break before?
  232.     */  
  233.  
  234.    if ( w->sgml_text.break_before )
  235.    {
  236.      _SGMLBreak(geom,w->sgml_text.space_before);
  237.    } 
  238.  
  239.    /*
  240.     * Query children?
  241.     */  
  242.  
  243.    for (; n-- > 0; children++)
  244.      {
  245.        SGMLTextObjectClass childClass = (SGMLTextObjectClass) XtClass(*children);
  246.  
  247.        if (geom->broken)
  248.          {
  249.            if (w->sgml_list_text.num_bullets == w->sgml_list_text.alloc_bullets)
  250.              w->sgml_list_text.bullets = (BulletList) XtRealloc((char *)w->sgml_list_text.bullets,
  251.                                                                 (w->sgml_list_text.alloc_bullets += 10) * sizeof(BulletListItem));
  252.              
  253.            w->sgml_list_text.bullets[w->sgml_list_text.num_bullets].x = x;  
  254.            w->sgml_list_text.bullets[w->sgml_list_text.num_bullets].y = geom->coord.y;  
  255.            w->sgml_list_text.num_bullets++;
  256.  
  257.            geom->coord.depth  = w->sgml_list_text.bullet_size;
  258.            geom->coord.ascent = w->sgml_list_text.bullet_size;
  259.         }    
  260.  
  261.        (*childClass->sgml_text_class.compute_size)(*children,geom,AdjustSize,*children);
  262.      }  
  263.  
  264.    /*
  265.     * Break after?
  266.     */  
  267.  
  268.    if ( w->sgml_text.break_after )
  269.    {
  270.      _SGMLBreak(geom,w->sgml_text.space_after);
  271.    } 
  272.  
  273. }
  274.  
  275. /*-----------------------------------------------------------------------*/
  276. /* Create a new SGMLListTextObject                                  */
  277. /*-----------------------------------------------------------------------*/
  278.  
  279. Widget SGMLCreateListText(parent,name,al,ac)
  280. Widget parent;
  281. char   *name;
  282. ArgList al;
  283. int     ac;
  284. {
  285.     return XtCreateWidget(name,sGMLListTextObjectClass,parent,al,ac);
  286. }
  287.